﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PES_TurnierManager.Model
{
    /// <summary>
    /// Simple structure holding the score of the Match
    /// </summary>
    public struct Score
    {
        public uint homeScore;
        public uint guestScore;
    }

    /// <summary>
    /// Indicates the Result of the Match without having to analyze
    /// the score
    /// </summary>
    public enum MatchResult
    {
        MR_HOME,
        MR_GUEST,
        MR_DRAW
    }

    /// <summary>
    /// A single Match with two participants. Encapsulates the result of a Match.
    /// </summary>
    public class Match
    {
        private HumanPlayer mHomePlayer;
        private HumanPlayer mGuestPlayer;
        private HumanPlayer mWinningPlayer;
        private bool mIsMatchePlayed;

        private uint mMatchID;

        private Score mScore;
        private MatchResult mResult;

        public Match(HumanPlayer home, HumanPlayer guest)
        {
            mHomePlayer = home;
            mGuestPlayer = guest;
            mIsMatchePlayed = false;
        }

        /// <summary>
        /// Sets the result of the Match.
        /// </summary>
        /// <param name="homeScore">score of home team</param>
        /// <param name="guestScore">score of guest team</param>
        public void setResult(uint homeScore, uint guestScore)
        {
            mScore.homeScore = homeScore;
            mScore.guestScore = guestScore;

            if (homeScore == guestScore)
                mResult = MatchResult.MR_DRAW;
            else if (homeScore > guestScore)
                mResult = MatchResult.MR_HOME;
            else
                mResult = MatchResult.MR_GUEST;

            mHomePlayer.addDataOfMatch(homeScore, guestScore);
            mGuestPlayer.addDataOfMatch(guestScore, homeScore);

            mIsMatchePlayed = true;
        }

        public string getHomeName()
        {
            return mHomePlayer.getPlayerName();
        }

        public string getGuestName()
        {
            return mGuestPlayer.getPlayerName();
        }

        public uint getHomeScore()
        {
            return mScore.homeScore;
        }

        public uint getGuestScore()
        {
            return mScore.guestScore;
        }

        public MatchResult getResult()
        {
            return mResult;
        }

        public uint getMatchID()
        {
            return mMatchID;
        }

        public void setMatchID(uint ID)
        {
            mMatchID = ID;
        }

        public bool isMatchPlayed()
        {
            return mIsMatchePlayed;
        }
    }
}
